<template>
	<view class="main">
		<view class="active_tit">
			<view class="tit">
				经营主体—基本信息
			</view> 
			<view  v-if="!isdisabled">
				<button  @click="chooseImg()" size="mini" type="primary">证件识别</button>
			</view>
		</view>
		<!-- input -->
		<ActiveForm required  ref='entName'>
			<view class="active_label">
				企业名称：
			</view>
			<view class="active_input">
				<input :disabled="isdisabled" type="text" v-model.trim="form.entName" />
			</view>
		</ActiveForm>
		
		<ActiveForm  required ref='frName'>
			<view class="active_label">
				法定代表人：
			</view>
			<view class="active_input">
				<input @input="znCheck($event,'frName')" type="text" v-model.trim="form.frName" />
			</view>
		</ActiveForm>
		<ActiveForm required  ref='actualController'>
			<view class="active_label">
				实际控制人：
			</view>
			<view class="active_input">
				<input type="text" @input="znCheck($event,'actualController')" v-model="form.actualController" />
			</view>
		</ActiveForm>
		<ActiveForm required  ref='empSums'>
			<view class="active_label">
				雇员人数：
			</view>
			<view class="active_input">
				<mInput :thousand='false' type="number" v-model="form.empSums" />
			</view>
		</ActiveForm>
		<ActiveForm required  ref='creditCode'>
			<view class="active_label">
				统一社会信用代码：
			</view>
			<view class="active_input">
				<input :disabled="isdisabled" maxlength="18" type="text" @input="cardCheck($event,'creditCode')" v-model.trim="form.creditCode" />
			</view>
		</ActiveForm>
		<ActiveForm required  ref='industry'>
			<view class="active_label">
				经营行业：
			</view>
			<view class="active_input">
				<SelectPicker :disabled='inDisabled' v-model="form.industry" :options="operatIndustry" placeholder="请选择经营行业" @change="selectIndustry" />
			</view>
		</ActiveForm>
		<ActiveForm required  ref='mainBusiness'>
			<view class="active_label">
				主营业务：
			</view>
			<view class="active_input">
				<input type="text" v-model="form.mainBusiness" />
			</view>
		</ActiveForm>
		
		<ActiveForm required  ref='busiAreaSource'>
			<view class="active_label">
				营业场地来源：
			</view>
			<view class="active_input">
				<SelectPicker v-model="form.busiAreaSource" :options="busiAreaSourceOption" placeholder="请选择营业场地来源" />
			</view>
		</ActiveForm>
		<ActiveForm required  ref='busiCount'>
			<view class="active_label">
				营业场所数量：
			</view>
			<view class="active_input">
				<input type="text" v-model="form.busiCount" />
			</view>
		</ActiveForm>
		<ActiveForm required  ref='busiArea'>
			<view class="active_label">
				营业场所面积(m²)：
			</view>
			<view class="active_input">
				<input type="text" v-model="form.busiArea" />
			</view>
		</ActiveForm>
	
		
		<ActiveForm required  ref='addressDetail'>
			<view class="active_label">
				营业详细地址：
			</view>
			<view class="active_input">
				<input type="text" v-model="form.addressDetail" />
			</view>
		</ActiveForm>
		<ActiveForm required  ref='operationYears'>
			<view class="active_label">
				经营年限(月)：
			</view>
			<view class="active_input">
				<!-- <input type="text" v-model="form.operationYears" /> -->
				<mInput negative :thousand='false'  v-model="form.operationYears"  />
			</view>
		</ActiveForm>
		<!-- <ActiveForm required  ref='busiHistory'>
			<view class="active_label">
				经营历史：
			</view>
			<view class="active_input">
				<input type="text" v-model="form.busiHistory" />
			</view>
		</ActiveForm>
		<ActiveForm required  ref='busiModelAndActuality'>
			<view class="active_label">
				经营模式及现状：
			</view>
			<view class="active_input">
				<input type="text" v-model="form.busiModelAndActuality" />
			</view>
		</ActiveForm> -->

	</view>
</template>

<script>
	import chooseImgToBase64 from "@/utils/chooseImgToBase64";
	import SelectPicker from "../../SelectPicker";
	import RegionPicker from "../../RegionPicker";
    import region from '../areaList.js'
	export default {
		name: 'activeForm',
		data() {
			return {
				region,
				isdisabled:false,
				province: "",
				city: "",
				county: "",
				index: 1,
				FxtData:[],
				form: {
					checked:'',
					entName:'',
					frName:'',
					actualController:'',
					empSums:'',
					creditCode:'',
					industry:'',
					mainBusiness:'',
					regTime:'',
					busiAreaSource:'',
					address:'',
					addressDetail:''
				},
				operatIndustry:[
					
				],
				busiAreaSourceOption: [
					
				],
				inDisabled:false
			}
		},
		props:{
			industry:{
				type: String,
				default: "1",
			},
			sceneType:''
		},
		onShow() {
			
		},
		watch:{
			sceneType:{
				handler:function(res){
					if(getApp().globalData.stdOffsurBaiscInfo.sceneType!=4&&getApp().globalData.stdOffsurBaiscInfo.sceneType!=5){//通用场景和无
						this.inDisabled = true
					}else{
						this.inDisabled = false
					}
				},
				deep:true
			},
			industry:{
				handler:function(res){
					console.warn('场景变化',res,)
					if(res==4){
						this.form.industry = '04'
					}else if(res==1){
						this.form.industry = '01'
					}else if(res==3){
						this.form.industry = '03'
					}
					if(getApp().globalData.stdOffsurBaiscInfo.sceneType!=4&&getApp().globalData.stdOffsurBaiscInfo.sceneType!=5){
						this.inDisabled = true
					}else{
						this.inDisabled = false
					}
					
					
				},
				deep:true
			},
			form:{
				handler:function(res){
					//console.warn('enterpriseInfo组件数据变化',res)
					getApp().globalData.stdOffsurEntBasic =res
				},
				deep:true
			}
		},
		computed:{
			address(){
				return function(val){
					//debugger
				        if(val==''||val==null){
				        	return []
				        }else{
				        	let arr = val.split(",")
				        	return arr
				        }
				      }
			}
		},
		components: {
			SelectPicker,
			RegionPicker
		},
		
		mounted() {
			
			//获取返显数据
			setTimeout(()=>{
				//获取下拉类型
				//经营行业
			   this.operatIndustry = getApp().globalData.optType.INDUSTRY_TYPE
				//营业场地来源
			   this.busiAreaSourceOption=getApp().globalData.optType.AREA_SOURCE
			  
				//数据反显
				if(JSON.stringify(getApp().globalData.stdOffsurEntBasic) != "{}"){
					this.form = getApp().globalData.stdOffsurEntBasic
				}
				this.isdisabled = getApp().globalData.entDisabled
			    
			},getApp().globalData.timeout)
		},
		methods:{
			//=====新增ocr============
			chooseImg() {
				chooseImgToBase64(
					(base64, base64SourceData, file) => {
						//console.log(base64SourceData)
						let imgData = {
							img: base64,
							base64: base64SourceData
						}
			
						console.log(imgData)
						this.ocrImg(base64SourceData)
			
					}, 500
			
				);
			},
			ocrImg(base64){
				this.sendRequest({
					url: 'businessLicense/businessLicenseRec',
					method: 'post',
					hideLoading: false,
					data: {
						"imageFile": base64,
					},
					complete: (res) => {
						if (res.code == '200'&&res.data.result==='0') {
							let cont = res.data.ocrResult
							for(let i=0;i<cont.length;i++){
								if(cont[i].fieldName==='统一社会信用代码'){
									this.form.creditCode = cont[i].fieldValue	
								}else if(cont[i].fieldName==='名称'){
									this.form.entName = cont[i].fieldValue	
								}else if(cont[i].fieldName==='法定代表人'){
									this.form.frName = cont[i].fieldValue	
								}
							}
						} else {
							uni.showToast({
								icon: "none",
								title: 'OCR识别失败，请重试',
								duration: 2000
							})
						}
					}
				})
				
			},
			znCheck(e,name){
				
				setTimeout(()=>{
					this.form[name] = e.target.value.replace(/[^\u4E00-\u9FA5]/g,'')
				},50)
			},
			cardCheck(e,name){
				setTimeout(()=>{
					this.form[name] = e.target.value.replace(/[^\a-\z\A-\Z0-9]/g,'')
				},50)
			},
			selectIndustry(){
				getApp().globalData.stdOffsurEntBasic.industry = this.form.industry
			}
		}
	}
</script>

<style lang="scss">
	
	
</style>
